package com.hl.controller;

import com.hl.domain.PsychologicalTopic.PsychologicalTopic;
import com.hl.domain.PsychologicalTopic.PsychologicalTopicReply;
import com.hl.service.serviceImpl.PsychologicalTopicServiceImpl;
import com.hl.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/psyopic")
public class PsychologicalTopicController {
    @Autowired
    private PsychologicalTopicServiceImpl psychologicalTopicService;
    @GetMapping("/topiclist")
    public R selectAllTopics(){
        List<PsychologicalTopic> topics = psychologicalTopicService.selectAllTopic();
        if (topics!=null){
            return R.success(topics);
        }else {
            return R.fail("查询失败");
        }
    }

    @GetMapping("/topicReplylist")
    public R selectReplyById(int i){
        List<PsychologicalTopicReply> replies = psychologicalTopicService.selectAllReplyByTopic(i);
        if (replies!=null){
            return R.success(replies);
        }else {
            return R.fail("查询失败");
        }
    }

    @PostMapping("/addreply")
    public R addReply(@RequestBody PsychologicalTopicReply reply){
        int i = psychologicalTopicService.addReply(reply);
        if (i>0){
            return R.success("回复成功");
        }else{
            return R.fail("回复失败");
        }
    }
    @PostMapping("/addtopic")
    public R addTopic(@RequestBody PsychologicalTopic topic){
        int i = psychologicalTopicService.addTopic(topic);
        if (i>0){
            return R.success("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }

    @DeleteMapping("/deletetopic")
    public R deleteTopic(Long i){
        int i1 = psychologicalTopicService.deleteTopic(i);
        if (i1>0){
            return R.success("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }

    @DeleteMapping("/deletetopicreply")
    public R deleteTopicReply(Long i){
        int i1 = psychologicalTopicService.deleteTopicReply(i);
        if (i1>0){
            return R.success("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }

}
